package monitor

import (
	"context"
	"google.golang.org/grpc"
	"qabx.net/safe-app-center/api/security_center_api"
)

func UnaryInterceptor(
	ctx context.Context,
	req interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (resp interface{}, err error) {
	if info.FullMethod == security_center_api.SecurityCenterApiService_PushTrafficLog_FullMethodName {
		NumPushTrafficLog.Inc()
	} else if info.FullMethod == security_center_api.SecurityCenterApiService_PushAppAnalyzeLog_FullMethodName {
		NumPushAppAnalyzeLog.Inc()
	} else if info.FullMethod == security_center_api.SecurityCenterApiService_PushInterceptLog_FullMethodName {
		NumPushInterceptLog.Inc()
	} else if info.FullMethod == security_center_api.SecurityCenterApiService_GetFeatureList_FullMethodName {
		NumGetFeatureList.Inc()
	} else if info.FullMethod == "UPLoadLeakScanLog" {
		NumUPLoadLeakScanLog.Inc()
	}

	// 调用下一个处理程序
	resp, err = handler(ctx, req)

	return resp, err
}
